# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-patience_diff
pkgver=1.2.0
pkgrel=1
pkgdesc='A Ruby implementation of the Patience diff algorithm'
arch=(any)
url='https://github.com/watt/ruby_patience_diff'
license=(MIT)
depends=(ruby-optimist)
makedepends=(ruby-hoe ruby-rake)
options=(!emptydirs)
source=(https://github.com/watt/ruby_patience_diff/archive/v$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('3c767f112c46ff7a4f42224897786187c845bacd06882fb3cfdf40208c6ac142')

prepare() {
  cd ruby_patience_diff-$pkgver
  sed -r -e 's|~>|>=|' -i Rakefile
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd ruby_patience_diff-$pkgver
  rake gem
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    pkg/patience_diff-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd ruby_patience_diff-$pkgver
  GEM_HOME="tmp_install/$_gemdir" rake test
}

package() {
  cd ruby_patience_diff-$pkgver
  cp -a tmp_install/* "$pkgdir"/
}
